import 'dart:async';
import 'package:bloc/bloc.dart';
import './bloc.dart';
import 'package:drm/base/tj_date_entity.dart';
import 'package:drm/http/date_result.dart';
import 'package:drm/char_view/two_entity.dart';

class ChartPageBloc extends Bloc<ChartPageEvent, ChartPageState> {
  @override
  ChartPageState get initialState => InitialChartPageState();

  @override
  Stream<ChartPageState> mapEventToState(
      ChartPageEvent event,
  ) async* {
    if (event is PageGetDateEvent) {
      DateResult<List<TjDateEntity>> result = await event.getHttpData();
      yield PageGetDateEventState(result,unit: event.unit);
    }

    if (event is PageGetTwoDateEvent) {
      DateResult<List<TwoEntity>> result = await event.getHttpData();
      yield PageGetTwoDateEventState(result);
    }

    if (event is PageGetThreeDateEvent) {
      DateResult<List<TjDateEntity>> result = await event.getHttpData();
      yield PageGetThreeDateEventState(result);
    }
  }
}
